//
//  ShoppingBuyViewController.m
//  HaoDeCaiFu
//
//  Created by admin on 2018/1/6.
//  Copyright © 2018年 郑开宏. All rights reserved.
//

#import "ShoppingBuyViewController.h"
#import "HDCFMyBankCardVc.h"//选择银行卡页面
#import "HDCFOpenAccountVc.h"//开户页面
#import "HDCFRiskTestVc.h"//风险评测
#import "InputPassWordView.h"
#import "ShoppingBuyTableViewCell.h"//cell
#import "jijinAndGroupDetailModel.h"//模型

static NSString * identifierOne = @"cell";
static NSString * identifierTwo = @"ShoppingBuyTableViewCell";

@interface ShoppingBuyViewController ()<UITableViewDelegate,UITableViewDataSource,InputPassWordViewDelegate,HDCFMyBankCardVcDelegate>
{
    NSArray * bankCardDataArray;//银行卡数组
    NSArray * bankNameArray;//银行名称数组
    NSInteger bankCardIndex;//银行卡的索引
    
    BOOL isEditOne;//是否修改过银行卡
    //在已经编辑过情况下使用的参数
    NSString * bankName;
    NSString * bankCode;
    NSString * bankIds;
    BOOL isBank;
    
    NSMutableArray * fundTypeArr;
    NSMutableArray * riskArr;
    
    NSMutableArray * salesChargesRateArr;//费率数组
    NSMutableArray * salesChargesArr;//费用数组
    
}
@property(nonatomic,strong)UITableView * tableView;
@property (nonatomic, weak) UIView *hitView;
@property (nonatomic, copy) NSString *tradePassword;
@end

@implementation ShoppingBuyViewController
-(void)setIsShop:(BOOL)isShop
{
    _isShop = isShop;
}
-(void)setShopArray:(NSArray *)shopArray
{
    _shopArray = shopArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"确认订单";
    
    bankCardDataArray = [NSArray array];
    isEditOne = NO;
    bankCardIndex = 0;
    fundTypeArr = [NSMutableArray array];
    riskArr = [NSMutableArray array];
    salesChargesRateArr = [NSMutableArray array];
    salesChargesArr = [NSMutableArray array];
    
    [self initTableView];
    [self initBottomView];
    //得到银行信息
    [self getBankName];
    //得到银行卡信息
    [self getBankCardInfo];
    //批量获取基金信息
    [self getDataOfBasic];
    //得到费率以及费用的请求
    [self getRateFee];
    // Do any additional setup after loading the view.
}
-(void)initTableView
{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = RGB(233, 233, 233);
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifierOne];
    [self.tableView registerNib:[UINib nibWithNibName:@"ShoppingBuyTableViewCell" bundle:nil] forCellReuseIdentifier:identifierTwo];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.frame = CGRectMake(0, 0, screenWidth, screenHeight - 49-KNavHeight);
        //_tableView.backgroundColor = [UIColor yellowColor];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
-(void)initBottomView
{
    //提交按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0 ,screenHeight - 49 -KNavHeight, screenWidth, 49);
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(shoppingCommit) forControlEvents:UIControlEventTouchUpInside];
    //[btn setBackgroundColor:ZKcolor(184, 27, 36)];
    [btn setBackgroundColor:COLOR_NAV];
    [self.view addSubview:btn];
}
#pragma mark -
#pragma mark requestData
//得到银行卡数据
- (void)getBankCardInfo{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:KBankCardInfo};
    
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        NSString *code = result[@"code"];
        if ([code isEqualToString:@"0000"]) {
            NSDictionary *dict = result[@"data"];
            NSDictionary *dictTwo = dict[@"investorBankDetails"];
            bankCardDataArray = dictTwo[@"data"];
            LLLog(@"%@",bankCardDataArray);
            [self.tableView reloadData];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"获取银行卡信息失败"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
- (void)getBankName{
    NSDictionary *paramet = @{
                              KparametTwo:@"/public/investor/find-bank"
                              };
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        //LLLog(@"%@",result);
        NSDictionary *dict = result[@"data"];
        bankNameArray = [NSArray arrayWithArray:dict[@"data"]];
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
//批量获取基金信息
- (void)getDataOfBasic{
    [SVProgressHUD show];
    NSMutableArray * fundcodeArray = [NSMutableArray array];
    NSDictionary *param = [NSDictionary dictionary];
    if (self.shopArray.count <= 0) {
        [SVProgressHUD dismiss];
        return;
    }
    for (int i = 0; i < self.shopArray.count; i++) {
        jijinAndGroupDetailModel * model = self.shopArray[i];
        [fundcodeArray addObject:model.fundCode];
    }
    NSString *string = [fundcodeArray componentsJoinedByString:@","];
    param = @{@"fundCodes":string};
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[KparametTwo] = @"/public/product/batch-get-fund-info";
    dict[KparametOne] = [self dictionaryToJson:param];
    [HttpRequest sendGetRequestWithURL:nil WithParamets:dict success:^(id result) {
        if ([result[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD dismiss];
            //LLLog(@"%@",result);
            NSDictionary * dataDic = result[@"data"];
            NSArray * dataArray = dataDic[@"data"];
            for (NSDictionary * dic in dataArray) {
                //[fundTypeArr addObject:dic[@"fundType"]];
                //[riskArr addObject:dic[@"riskRate"]];
                [fundTypeArr insertObject:dic[@"fundType"] atIndex:0];
                [riskArr insertObject:dic[@"riskRate"] atIndex:0];
            }
            
            //一个section刷新
            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
            [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }else{
            [SVProgressHUD showErrorWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
//购物车购买请求
-(void)shoppingBuyRequest
{
    [SVProgressHUD show];
    NSMutableArray * purchaseArr = [NSMutableArray array];
    for (int i = 0; i < _shopArray.count; i++) {
        jijinAndGroupDetailModel * jiModel = [[jijinAndGroupDetailModel alloc]init];
        jiModel = _shopArray[i];
        NSMutableDictionary *fundInfo = [NSMutableDictionary dictionary];
        fundInfo[@"fundCode"] = jiModel.fundCode;
        fundInfo[@"currency"] = @"156";
        fundInfo[@"investmentAmount"] = jiModel.Amount;
        
        [purchaseArr addObject:fundInfo];
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"accountNumber"] = kAcount;
    dict[@"agreementConfirmed"] = @"0";
    
    dict[@"password"] = self.tradePassword;
    //支付方式.0=银行卡，1=现金钱包支付，2=线下支付,3=商户代扣
    if (isEditOne == NO) {
        if (bankCardDataArray.count > 0) {
            dict[@"payMethod"] = @"0";
            dict[@"investorPayId"] = bankCardDataArray[0][@"investorPayId"];
        }
        else
        {
            return;
        }
    }
    else
    {
        if (isBank==YES) {
            dict[@"payMethod"] = @"0";
            dict[@"investorPayId"] = bankIds;
        }
        else
        {
            dict[@"payMethod"] = @"1";
        }
    }
    dict[@"purchaseFunds"] = purchaseArr;
    dict[@"riskConfirmed"] = @"1";
    NSString *jsonString = [self dictionaryToJson:dict];
    NSDictionary *dictThree = @{
                                KparametTwo:@"/public/transaction/buy-fund-transaction"
                                };
    [HttpRequest sendPostRequestWithURL:nil WithParamets:dictThree WithJsonString:jsonString success:^(id result) {
        
        //NSLog(@"%@",result);
        
        if ([result[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showSuccessWithStatus:@"购买成功"];
            [SVProgressHUD dismissWithDelay:1.0];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
            
            self.block(_shopArray);
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误，购买失败"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
//得到费率以及费用的请求
- (void)getRateFee
{
    [salesChargesRateArr removeAllObjects];
    [salesChargesArr removeAllObjects];
    
    for (int i = 0; i < _shopArray.count; i++)
    {
        jijinAndGroupDetailModel * jiModel = [[jijinAndGroupDetailModel alloc]init];
        jiModel = _shopArray[i];
        NSMutableDictionary *fundInfo = [NSMutableDictionary dictionary];
        fundInfo[@"fundCode"] = jiModel.fundCode;
        fundInfo[@"investmentAmount"] = jiModel.Amount;
        
        NSString *jsonStr = [self dictionaryToJson:fundInfo];
        NSDictionary *paramet = @{KparametOne:jsonStr,
                                  KparametTwo:KGetFee};
        [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
            
            NSString *code = result[@"code"];
            if ([code isEqualToString:@"0000"]) {
                NSDictionary *dict = result[@"data"];
                
                NSNumber *salesChargesRate;//费率
                NSNumber *salesCharges;//费用
                if (![dict[@"salesChargesRate"] isKindOfClass:[NSNull class]]) {
                    salesChargesRate = dict[@"salesChargesRate"];
                    [salesChargesRateArr addObject:salesChargesRate];
                    //self.consultRate.text = [NSString stringWithFormat:@"%.2f%%", salesChargesRate.doubleValue];
                }
                else
                {
                    [salesChargesRateArr addObject:@0];
                }
                
                if (![dict[@"salesCharges"] isKindOfClass:[NSNull class]]) {
                    salesCharges = dict[@"salesCharges"];
                    [salesChargesArr addObject:salesCharges];
                    //self.consultCost.text = [NSString stringWithFormat:@"%.2f元", salesCharges.doubleValue];
                }
                else
                {
                    [salesChargesArr addObject:@0];
                }
            }else{
                [SVProgressHUD showInfoWithStatus:result[@"message"]];
                [SVProgressHUD dismissWithDelay:1.0];
                
                [salesChargesRateArr addObject:@0];
                [salesChargesArr addObject:@0];
            }
        } failure:^(NSError *errer) {
            [SVProgressHUD showErrorWithStatus:@"服务器错误"];
            [SVProgressHUD dismissWithDelay:1.0];
            
            [salesChargesRateArr addObject:@0];
            [salesChargesArr addObject:@0];
        }];
    }
    //刷新对应的section
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark -
#pragma mark 事件
//提交
-(void)shoppingCommit
{
    //LLLog(@"%@",_dataDic);
    //先判断是否登录
    NSString *token = kToken;
    if (!(token.length > 0)) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请先登录！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            HDCFLoginVc *loginVc = [[HDCFLoginVc alloc] init];
            [self.navigationController pushViewController:loginVc animated:NO];
            
        }];
        UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alert addAction: action1];
        [alert addAction: action2];
        [self presentViewController:alert animated:NO completion:nil];
        return;
    }
    
    //在判断是否开户
    NSString *openStatus = kOpenStatus;
    if (!(openStatus.integerValue > 0)){
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请先开户！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            HDCFOpenAccountVc *loginVc = [[HDCFOpenAccountVc alloc] init];
            [self.navigationController pushViewController:loginVc animated:NO];
            
        }];
        UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alert addAction: action1];
        [alert addAction: action2];
        [self presentViewController:alert animated:NO completion:nil];
        return;
    }
    
    NSNumber *selfRiskRate = kRiskResult;
    if (!selfRiskRate) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请先进行风险评测！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            HDCFRiskTestVc *riskVc = [[HDCFRiskTestVc alloc] init];
            [self.navigationController pushViewController:riskVc animated:NO];
            
        }];
        UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alert addAction: action1];
        [alert addAction: action2];
        [self presentViewController:alert animated:NO completion:nil];
        return;
    }
    
    
    for (int i = 0; i < riskArr.count; i++) {
        NSNumber *funfRiskRate = riskArr[i];
        //如果自己是保守型，那么除了保守型基金其他都不能购买
        if ([selfRiskRate isEqual:@1]) {
            if (funfRiskRate.integerValue > selfRiskRate.integerValue) {
                [SVProgressHUD showInfoWithStatus:@"您的风险等级为保守型，不能购买超过风险等级的产品"];
                [SVProgressHUD dismissWithDelay:1.5];
                return;
            }
            
        }
        
        if (funfRiskRate.integerValue > selfRiskRate.integerValue) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"友情提示" message:@"此基金的购买风险超出您的风险承受能力，确定要购买吗？" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                UIWindow *window = [UIApplication sharedApplication].keyWindow;
                UIView *view = [[UIView alloc] init];
                self.hitView = view;
                UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewHit)];
                r5.numberOfTapsRequired = 1;
                [view addGestureRecognizer:r5];
                
                view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
                view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
                InputPassWordView *inputView = [InputPassWordView InputPassWordView];
                inputView.frame = CGRectMake(30, (screenHeight - 182) / 2, screenWidth - 60, 182);
                inputView.layer.cornerRadius = 5.0;
                inputView.layer.shadowColor = ZKcolor(100, 100, 100).CGColor;//shadowColor阴影颜色
                inputView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
                inputView.layer.shadowOpacity = 0.7;//阴影透明度，默认0
                inputView.layer.shadowRadius = 3;//阴影半径，默认3
                inputView.clipsToBounds = YES;
                inputView.delegate = self;
                
                [view addSubview:inputView];
                [window addSubview:view];
            }];
            UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alert addAction: action1];
            [alert addAction: action2];
            [self presentViewController:alert animated:NO completion:nil];
            
            return;
        }
//        else{
//            UIWindow *window = [UIApplication sharedApplication].keyWindow;
//            UIView *view = [[UIView alloc] init];
//            self.hitView = view;
//            UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewHit)];
//            r5.numberOfTapsRequired = 1;
//            [view addGestureRecognizer:r5];
//
//            view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
//            view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
//            InputPassWordView *inputView = [InputPassWordView InputPassWordView];
//            inputView.frame = CGRectMake(30, (screenHeight - 182) / 2, screenWidth - 60, 182);
//            inputView.layer.cornerRadius = 5.0;
//            inputView.layer.shadowColor = ZKcolor(100, 100, 100).CGColor;//shadowColor阴影颜色
//            inputView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
//            inputView.layer.shadowOpacity = 0.7;//阴影透明度，默认0
//            inputView.layer.shadowRadius = 3;//阴影半径，默认3
//            inputView.clipsToBounds = YES;
//            inputView.delegate = self;
//
//            [view addSubview:inputView];
//            [window addSubview:view];
//        }
    }
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIView *view = [[UIView alloc] init];
    self.hitView = view;
    UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewHit)];
    r5.numberOfTapsRequired = 1;
    [view addGestureRecognizer:r5];
    
    view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
    view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
    InputPassWordView *inputView = [InputPassWordView InputPassWordView];
    inputView.frame = CGRectMake(30, (screenHeight - 182) / 2, screenWidth - 60, 182);
    inputView.layer.cornerRadius = 5.0;
    inputView.layer.shadowColor = ZKcolor(100, 100, 100).CGColor;//shadowColor阴影颜色
    inputView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    inputView.layer.shadowOpacity = 0.7;//阴影透明度，默认0
    inputView.layer.shadowRadius = 3;//阴影半径，默认3
    inputView.clipsToBounds = YES;
    inputView.delegate = self;
    
    [view addSubview:inputView];
    [window addSubview:view];
    //NSNumber *funfRiskRate = [NSNumber numberWithInteger:riskRate];
    
}
//定投规则
-(void)fixThrowRule
{
    
}
- (void)viewHit{
    [self.hitView removeFromSuperview];
}
#pragma mark -
#pragma mark UITableViewDelegate,UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifierOne];
    if (!cell) {
        cell = [tableView dequeueReusableCellWithIdentifier:identifierOne forIndexPath:indexPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        if (isEditOne == NO) {
            if (bankCardDataArray.count > 0)
            {
                UIView * cellView = [[UIView alloc]init];
                cellView.backgroundColor = [UIColor whiteColor];
                cellView.frame = CGRectMake(0, 0, screenWidth, 50+30);
                [cell addSubview:cellView];
                
                UILabel * firstLabel = [[UILabel alloc]init];
                firstLabel.text = @"支付方式";
                firstLabel.font = [UIFont systemFontOfSize:12];
                firstLabel.frame = CGRectMake(10, 15, [self calculateWidth:firstLabel.text], 20);
                firstLabel.textColor = RGB(0,0,0);
                [cellView addSubview:firstLabel];
                
                
                NSDictionary * dict = bankCardDataArray[bankCardIndex];
                NSString *banName;
                NSString *cardNo;
                NSString *laterFour;
                for (int i = 0; i < bankNameArray.count; i++) {
                    NSDictionary * bankNameDict = bankNameArray[i];
                    if ([bankNameDict[@"bankCode"] isEqualToString:dict[@"bankCode"]])
                    {
                        banName = bankNameDict[@"bankName"];
                        cardNo = dict[@"bankNumber"];
                        laterFour = [cardNo substringFromIndex:(cardNo.length - 4)];
                        break;
                    }
                }
                UILabel * secondLabel = [[UILabel alloc]init];
                if ([banName isKindOfClass:[NSNull class]] || [laterFour isKindOfClass:[NSNull class]]) {
                    secondLabel.text = [NSString stringWithFormat:@"---"];
                }
                else
                {
                    secondLabel.text = [NSString stringWithFormat:@"%@  ***%@", banName, laterFour];
                }
//                if (isEditOne == NO) {
//                    //使用model类给值
//                    NSString * cardStr = [_fixThrowPlanListModel.investorPayBankAccountNumber substringFromIndex:(cardNo.length - 4)];
//                    secondLabel.text = [NSString stringWithFormat:@"%@  ***%@", _fixThrowPlanListModel.investorPayBankName, cardStr];
//                }
                secondLabel.font = [UIFont systemFontOfSize:14];
                secondLabel.frame = CGRectMake(10, firstLabel.bottom + 5, [self calculateWidth:secondLabel.text], 20);
                secondLabel.textColor = RGB(0,0,0);
                [cellView addSubview:secondLabel];
                
                UIImageView * rightImageView = [[UIImageView alloc]init];
                rightImageView.frame = CGRectMake(screenWidth -10 -20, 26, 20, 20);
                rightImageView.image = [UIImage imageNamed:@"icon_right"];
                [cellView addSubview:rightImageView];
                
                UIView * bottomView = [[UIView alloc]init];
                bottomView.frame = CGRectMake(0, 72, screenWidth, 8);
                bottomView.backgroundColor = RGB(233, 233, 233);
                [cellView addSubview:bottomView];
            }
            else
            {
                UIView * cellView = [[UIView alloc]init];
                cellView.backgroundColor = [UIColor whiteColor];
                cellView.frame = CGRectMake(0, 0, screenWidth, 50+30);
                [cell addSubview:cellView];
                
                
                UIView * headerTwoView = [UIView new];
                headerTwoView.frame = CGRectMake(0, 0, screenWidth, 30);
                headerTwoView.backgroundColor = RGB(253,245,230);
                [cellView addSubview:headerTwoView];
                
                UIImageView * imageView = [[UIImageView alloc]init];
                imageView.frame = CGRectMake(10, 5, 20, 20);
                imageView.image = [UIImage imageNamed:@"icon_tanhao"];
                [headerTwoView addSubview:imageView];
                
                
                UILabel * titleLabel = [[UILabel alloc]init];
                titleLabel.text = @"您需要绑定银行卡才能进行交易";
                titleLabel.font = [UIFont systemFontOfSize:14];
                titleLabel.frame = CGRectMake(imageView.right +10, 5, [self calculateWidth:titleLabel.text], 20);
                titleLabel.textColor = RGB(255,165,0);
                [headerTwoView addSubview:titleLabel];
                
                
                
                UIImageView * addImageView = [[UIImageView alloc]init];
                addImageView.frame = CGRectMake(10, 40, 20, 20);
                addImageView.image = [UIImage imageNamed:@"icon_add"];
                [cellView addSubview:addImageView];
                
                UILabel * titlesLabel = [[UILabel alloc]init];
                titlesLabel.text = @"添加银行卡";
                titlesLabel.font = [UIFont systemFontOfSize:14];
                titlesLabel.frame = CGRectMake(addImageView.right +10, 40, [self calculateWidth:titlesLabel.text], 20);
                titlesLabel.textColor = RGB(255,165,0);
                [cellView addSubview:titlesLabel];
                
                UIImageView * rightImageView = [[UIImageView alloc]init];
                rightImageView.frame = CGRectMake(screenWidth -10 -20, 40, 20, 20);
                rightImageView.image = [UIImage imageNamed:@"icon_right"];
                [cellView addSubview:rightImageView];
                
                UIView * bottomView = [[UIView alloc]init];
                bottomView.frame = CGRectMake(0, 72, screenWidth, 8);
                bottomView.backgroundColor = RGB(233, 233, 233);
                [cellView addSubview:bottomView];
            }
        }
        else
        {
            //编辑过
            UIView * cellView = [[UIView alloc]init];
            cellView.backgroundColor = [UIColor whiteColor];
            cellView.frame = CGRectMake(0, 0, screenWidth, 50+30);
            [cell addSubview:cellView];
            
            UILabel * firstLabel = [[UILabel alloc]init];
            firstLabel.text = @"支付方式";
            firstLabel.font = [UIFont systemFontOfSize:12];
            firstLabel.frame = CGRectMake(10, 15, [self calculateWidth:firstLabel.text], 20);
            firstLabel.textColor = RGB(0,0,0);
            [cellView addSubview:firstLabel];
            
            
            UILabel * secondLabel = [[UILabel alloc]init];
            if (isBank) {
                secondLabel.text = [NSString stringWithFormat:@"%@  ***%@", bankName, bankCode];
            }
            else
            {
                secondLabel.text = [NSString stringWithFormat:@"现金钱包 余额：%.2f元",[bankName floatValue]];
            }
            secondLabel.font = [UIFont systemFontOfSize:14];
            secondLabel.frame = CGRectMake(10, firstLabel.bottom + 5, [self calculateWidth:secondLabel.text], 20);
            secondLabel.textColor = RGB(0,0,0);
            [cellView addSubview:secondLabel];
            
            UIImageView * rightImageView = [[UIImageView alloc]init];
            rightImageView.frame = CGRectMake(screenWidth -10 -20, 26, 20, 20);
            rightImageView.image = [UIImage imageNamed:@"icon_right"];
            [cellView addSubview:rightImageView];
            
            UIView * bottomView = [[UIView alloc]init];
            bottomView.frame = CGRectMake(0, 72, screenWidth, 8);
            bottomView.backgroundColor = RGB(233, 233, 233);
            [cellView addSubview:bottomView];
        }
        
    }
    else if (indexPath.section == 1)
    {
        ShoppingBuyTableViewCell * shopCell = [tableView dequeueReusableCellWithIdentifier:identifierTwo forIndexPath:indexPath];
        shopCell.selectionStyle = UITableViewCellSelectionStyleNone;
        shopCell.backgroundColor = RGB(233, 233, 233);
        
        jijinAndGroupDetailModel * jijinModel = _shopArray[indexPath.row];
        
        shopCell.fundNameLabel.text = jijinModel.fundName;
        
        NSArray * typeEArr = @[@"MM",@"BOND",@"MIXED",@"CP",@"EQ",@"AI",@"INDEX",@"ST",@"UNKNOWN"];
        NSArray * typeCArr = @[@"货币型",@"债券型",@"混合型",@"保本型",@"股票型",@"另类型",@"指数型",@"分级型",@"其他"];
        NSString * typeC;
        if (fundTypeArr.count > 0) {
            for (int i = 0;i < typeEArr.count;i++)
            {
                NSString * typeE = typeEArr[i];
                if ([typeE isEqualToString:fundTypeArr[indexPath.row]]) {
                    typeC = typeCArr[i];
                    break;
                }
            }
            shopCell.fundCodeLabel.text = [NSString stringWithFormat:@"%@   %@",jijinModel.fundCode,typeC];
        }
        else
        {
            shopCell.fundCodeLabel.text = [NSString stringWithFormat:@"%@",jijinModel.fundCode];
        }
        
        if (riskArr.count > 0) {
            NSNumber *riskRate = riskArr[indexPath.row];
            if (riskRate.integerValue == 1) {
                //_riskLevel.text = @"保守型";
                shopCell.riskLevelImageView.image = [UIImage imageNamed:@"di"];
            }else if (riskRate.integerValue == 2){
                //_riskLevel.text = @"中度保守型";
                shopCell.riskLevelImageView.image = [UIImage imageNamed:@"zhongdi"];
            }else if (riskRate.integerValue == 3){
                //_riskLevel.text = @"平衡型";
                shopCell.riskLevelImageView.image = [UIImage imageNamed:@"zhong"];
            }else if (riskRate.integerValue == 4){
                //_riskLevel.text = @"中度进取型";
                shopCell.riskLevelImageView.image = [UIImage imageNamed:@"zhonggao"];
            }else{
                //_riskLevel.text = @"进取型";
                shopCell.riskLevelImageView.image = [UIImage imageNamed:@"gao"];
            }
        }
        else
        {
            shopCell.riskLevelImageView.image = [UIImage imageNamed:@"no_image"];
        }
        
        shopCell.buyAmountLabel.text = [NSString stringWithFormat:@"购买金额：%.2f元",[jijinModel.Amount floatValue]];
        
        //shopCell.investGroupLabel
        
        if (salesChargesRateArr.count == _shopArray.count ) {
            shopCell.rateLabel.text = [NSString stringWithFormat:@"参考费率：%.2f%%",[salesChargesRateArr[indexPath.row] floatValue]];
        }
        else
        {
            shopCell.rateLabel.text = [NSString stringWithFormat:@"参考费率：0.00%%"];
        }
        
        if (salesChargesArr.count == _shopArray.count) {
            shopCell.costLabel.text = [NSString stringWithFormat:@"参考费用：%.2f元",[salesChargesArr[indexPath.row] floatValue]];
        }
        else
        {
            shopCell.costLabel.text = [NSString stringWithFormat:@"参考费用：0.00元"];
        }
        
        
        return shopCell;
    }
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return _shopArray.count;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 80;
    }
    else if (indexPath.section == 1)
    {
        return 150.0;
    }
    return 150.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        //点击添加银行卡
        HDCFMyBankCardVc * bankCardVC = [[HDCFMyBankCardVc alloc]init];
        bankCardVC.isXianshiWallet = YES;
        bankCardVC.delegate = self;
        
        bankCardVC.isHiddenDeleteBtn = YES;
        bankCardVC.isNeedBlock = YES;
        [bankCardVC setBlock:^(NSString *name, NSString *bank, NSString *bankId, BOOL isBankCard) {
            LLLog(@"%@ %@ %@ %d",name,bank,bankId,isBankCard);
            bankName = name;
            bankCode = bank;
            bankIds = bankId;
            isBank = isBankCard;
            
            isEditOne = YES;
            //一个section刷新
            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
            [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }];
        [self.navigationController pushViewController:bankCardVC animated:YES];
    }
}
#pragma mark -
#pragma mark HDCFMyBankCardVcDelegate
-(void)HDCFMyBankCardVcReturnSelectIndex:(NSInteger)index
{
    isEditOne = YES;
    bankCardIndex = index;
    //一个section刷新
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark -
#pragma mark InputPassWordViewDelegate
- (void)cancelClick{
    [self.hitView removeFromSuperview];
}
- (void)confirmClickWithPassWord:(NSString *)password{
    self.tradePassword = password;
    [self.hitView removeFromSuperview];
    if (password.length < 1) {
        [SVProgressHUD showInfoWithStatus:@"请输入交易密码"];
        [SVProgressHUD dismissWithDelay:1.0];
        return;
    }
    
    [self shoppingBuyRequest];
}
#pragma mark -
#pragma mark 计算字符串长度
- (CGFloat)calculateWidth:(NSString *)str {
    NSDictionary *dic  = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    CGSize size = [str sizeWithAttributes:dic];
    return size.width;
}
#pragma mark -
#pragma mark 字典转json字符串
- (NSString *)dictionaryToJson:(NSDictionary *)dic{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString *jsonTemp = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return jsonTemp;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
